package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.AreaService;
import com.yixun.qfbao.apidto.GetAreaAndPremisesCountReqDto;
import com.yixun.qfbao.apidto.GetPremisesAreaListResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetAreaAndPremisesCountReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GetAreaAndPremisesCountHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetAreaAndPremisesCountHander.class);

    @Autowired
    private AreaService areaService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetPremisesAreaListResDto> res = new BaseResponseDTO<>();
        GetAreaAndPremisesCountReqVo reqVo = (GetAreaAndPremisesCountReqVo) reqDto;
        GetAreaAndPremisesCountReqDto getAreaAndPremisesCountReqDto = reqVo.getParams();
        try {
            GetPremisesAreaListResDto resDto = areaService.getAreaAndPremisesCount(getAreaAndPremisesCountReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("GetAreaAndPremisesCountHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("获取市区列表失败");
        }
        return res;
    }
}
